(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/cases/02_ui/03_button/SimpleButton/SimpleButtonCtrl.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '68675KwfElAdaumPl1byNh7', 'SimpleButtonCtrl', __filename);
// cases/02_ui/03_button/SimpleButton/SimpleButtonCtrl.js

'use strict';

var i18n = require('i18n');

cc.Class({
    extends: cc.Component,

    properties: {
        buttonLeft: cc.Button,
        buttonRight: cc.Button,
        display: cc.Label
    },

    onLoad: function onLoad() {
        var _this = this;

        cc.loader.loadRes("test assets/atlas", cc.SpriteAtlas, function (err, atlas) {
            var frame = atlas.getSpriteFrame('sheep_run_0');
            var node = new cc.Node('Button');
            var sp = node.addComponent(cc.Sprite);
            sp.spriteFrame = frame;
            node.setPosition(0, 0);
            node.parent = _this.node;
        });

        // 创建一个Label
        var labelNode = new cc.Node("Label");
        var label = labelNode.addComponent(cc.Label);
        label.string = "Label";
        labelNode.setPosition(100, 100);
        labelNode.setContentSize(200, 40);
        labelNode.parent = this.node;

        console.log(this);

        // 添加按钮
        cc.loader.loadRes("test assets/btn_options", cc.SpriteFrame, function (err, spriteFrame) {

            console.log("cc.loader.loadRes = ", this);

            var buttonNode = new cc.Node("CustomButton");
            var button = buttonNode.addComponent(cc.Button);
            button.normalColor = cc.Color.GRAY;
            button.pressedColor = cc.Color.RED;
            button.interactable = true;
            buttonNode.setPosition(200, 100);
            buttonNode.setContentSize(100, 80);
            buttonNode.parent = _this.node;

            var buttonSprite = buttonNode.addComponent(cc.Sprite);
            buttonSprite.spriteFrame = spriteFrame;
            buttonSprite.type = cc.Sprite.Type.SLICED;
            buttonSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;

            var eventHandler = new cc.Component.EventHandler();
            eventHandler.target = buttonNode;
            eventHandler.component = "SimpleButtonCtrl";
            eventHandler.handler = "OnClick";
            // button.clickEvents.push(eventHandler);

            buttonNode.on('click', _this.onCustomButtonClick, _this);
        });

        this.buttonLeft.node.setPosition(0, 0);
        this.display.node.setPosition(16, 260);
    },

    onBtnLeftClicked: function onBtnLeftClicked() {
        console.log('Left button clicked!');
        this.display.textKey = i18n.t("cases/02_ui/03_button/SimpleButton.js.1");
    },

    onBtnRightClicked: function onBtnRightClicked() {
        console.log('Right button clicked!');
        this.display.textKey = i18n.t("cases/02_ui/03_button/SimpleButton.js.2");
    },

    onCustomButtonClick: function onCustomButtonClick() {
        console.log('Custom Button Clicked');
        this.display.string = "Custom Button Clicked";
    }
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=SimpleButtonCtrl.js.map
        